package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.mappers.AnnouncementsMapper;
import com.tanhua.model.domain.Announcement;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author wjs
 * @version 1.0
 * @date 2021/12/30 0030 下午 2:51
 */

@DubboService
public class AnnouncementsApiImpl implements AnnouncementsApi{

    @Autowired
    private AnnouncementsMapper  announcementsMapper;

    @Override
    public List<Announcement> findPage(Integer page, Integer pagesize) {

        IPage iPage = new Page(page,pagesize);
        LambdaQueryWrapper<Announcement> lqw = new LambdaQueryWrapper<>();
        lqw.orderByDesc(Announcement::getCreated);
        lqw.select(Announcement::getId,Announcement::getTitle,Announcement::getDescription,Announcement::getCreated);
        announcementsMapper.selectPage(iPage, lqw);

        return iPage.getRecords();
    }

    @Override
    public Long findCount() {
        Integer count = announcementsMapper.selectCount(null);

        return Long.valueOf(count);
    }
}
